<?php
/**
 * Created by PhpStorm.
 * User: chen
 * Date: 2016/4/21
 * Time: 12:02
 */

namespace services\models;

use common\models\ClockInLog;
use Yii;

class ClockIn extends ClockInLog{


    /*
     * 是否打过卡
     * 是true，否false
     * */
    public static function is_DaKa($lkt_uid){
        $today = date('Ymd');

        $r = Yii::$app->redis->zscore( 'registration_' . $lkt_uid, $today );
        return $r > 0 ? true : false;
    }

    /*
     * 打卡
     * 存入mysql，录入redis
     * */
    public function DaKa($lkt_uid){

        if(!$this->is_Daka($lkt_uid)){
            $DaKa = new ClockInLog();
            $DaKa->create_day = date('Ymd');
            $DaKa->member_no = $lkt_uid;
            $DaKa->addtime = time();
            if($DaKa->save()){
                Yii::$app->redis->zadd('registration_'.$DaKa->member_no,time(),date('Ymd'));
                return true;
            }
        }
        return false;
    }

}